<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>Insert title here</title>
	<script type="text/javascript" src="jquery-3.7.1.min.js"></script>
	<script type="text/javascript">
		window.onload = function () {
			$("#login").click(function () {
				$.get("http://127.0.0.1:8080/user/login?username=jim", function (data, status) {
					const obj = JSON.parse(data);
					const token = obj.token
					alert("token is: " + token);
					window.localStorage.setItem('token', token); //存储数据
				});
			});
			$("#token").click(function () {
				$.get("http://127.0.0.1:8080/user/token?username=jim", function (data, status) {
					const obj = JSON.parse(data);
					const token = obj.token
					alert("token is: " + token);
					var tokenLocal = window.localStorage.getItem('token', token); //存储数据
					if(token === tokenLocal){
						alert("token匹配");
					}else {
						alert("token不匹配");
					}
				});
			});
		}
	</script>
</head>

<body>
	<input id="login" type="button" style="margin:100px;" value="登录" />
	<input id="token" type="button" value="获取token" />
</body>

</html>